﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Controls;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Database;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>
    public partial class WB03WB : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        INTEXDataSet iNTEXDataSet;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        //private Dictionary<string, object> dicQueryParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        WB03WBData m_Data, m_DataX;
        WB03WBReport m_rpt;
        public DataSet dsParamaters;
        
        DataRow dwUI;
        DataTable tbUI;
        private string fromorderdate = "", endorderdate = ""
    , fromincomedate = "", endincomedate = "";
        private string m_GSART, m_GSVAR, m_GSCOLOR, m_Supplier;
        #endregion
        public WB03WB()
        {
            InitializeComponent();
            this.Name = "成品结存";
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        { 
            base.SetUp(dicParamater);
            InitializeComponent();
            
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            dsParamaters = (DataSet)dicParamater["dsParamaters"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = this.OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new WB03WBData();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            m_rpt = new WB03WBReport(dicParamater);
            using (new LongOperation(this, "读取符合条件的记录"))
            {
                InitDataBinding();
            }
        }
        private void ItemsControls_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        } 
        private void InitDataBinding()
        {
            try
            {
                iNTEXDataSet = ((INTEXDataSet)(this.FindResource("iNTEXDataSet")));
                setUI = (DataSet)TryFindResource("setUI");
                if (setUI == null)
                {
                    setUI = new DataSet();
                }
                tbUI = new DataTable("TableUI"); 
                dwUI = tbUI.NewRow(); 
                this.setUI.Tables.Clear();
                this.txtArticle.Text = "";
                this.txtBATCH.Text = "";
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
       private void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string ARTICLE = this.txtArticle.Text.Trim();
                string BATCH = this.txtBATCH.Text.Trim();
                if (ARTICLE =="")
                {
                    ARTICLE = "A";
                }
                if (BATCH =="")
                {
                    BATCH = "A";
                }
                DataTable tbUI = new DataTable("TableUI");
                tbUI.Columns.Add("ARTICLE", typeof(string));
                tbUI.Columns.Add("BATCH", typeof(string));
                DataRow dwUI = tbUI.NewRow();
                dwUI["ARTICLE"] = ARTICLE;
                dwUI["BATCH"] = BATCH;
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = new DataSet();
                    setResult = m_Data.BuildData(setResult, dwUI);
                    setUI.Clear();
                    setUI.Merge(setResult);
                    this.MasterData.DataContext = setUI;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnReport_Click(object sender, RoutedEventArgs e)
        {
            m_DataX = new WB03WBData(dicParamater);
            m_DataX.OracleDB = this.OracleDB;
            m_DataX.proxy = this.proxy;
            m_rpt.exAgent = m_DataX.exAgent;
            m_rpt.dsSource = setUI;
            m_rpt.REPORT2EXCEL("EXCEL"); 
        }

        private void btnQuery1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string ARTICLE = this.txtArticle.Text.Trim();
                string BATCH = this.txtBATCH.Text.Trim();
                if (ARTICLE == "")
                {
                    ARTICLE = "A";
                }
                if (BATCH == "")
                {
                    BATCH = "A";
                }
                DataTable tbUI = new DataTable("TableUI");
                tbUI.Columns.Add("ARTICLE", typeof(string));
                tbUI.Columns.Add("BATCH", typeof(string));
                DataRow dwUI = tbUI.NewRow();
                dwUI["ARTICLE"] = ARTICLE;
                dwUI["BATCH"] = BATCH;
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = new DataSet();
                    setResult = m_Data.BuildData1(setResult, dwUI);
                    setUI.Clear();
                    setUI.Merge(setResult);
                    this.MasterData.DataContext = setUI;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        } 
    }
}